

var frameCount = 0;
var frameCurrent = 0;
var frameIsRunning = 0;

var animationItems = new Array();
var animationLastItem = 0; 

var imageCacheList = new Array();

function preloadList()
{
 /*   var listCounter = 0;

	if(listCounter <= title_list.length)
    {
        //document.getElementById("main_image").setAttribute("src",title_list[listCounter]);
        imageCacheList[listCounter] = new Image();
        imageCacheList[listCounter].src = title_list[listCounter];
        listCounter++;
    }
*/
}

function animationInit()
{
    preloadList();
    spawn_thread(animationLoop, animationLoop, 100, 0);
};


function animationLoop()
{
	//if(slider_tag && counter <= title_list.length)
    //{
      //  document.getElementById("main_image") = imageCacheList[listCounter];
      //  counter++;
    //}
};

var Animation = function(name,frame,type,src)
{
	this.type = type;
	this.frame = frame;
	this.name = name;
	this.array = src;
	this.frameCount = src.length;
	this.framerate = 2500;
	this.lock = 1;
	this.currentFrame = 0; 
	
	this.init = function()
	{
		
	};
	
	this.buffer = function()
	{
		
	};

	this.togglePlayback = function()
	{

		if(this.lock == 1)
		{
			this.lock = 0;
			return;
		}
		else 
			this.lock = 1;		
		
		return;
	};
	
	this.pause = function()
	{
		this.lock = 1;
	};
	
	this.play = function()
	{
		this.lock = 0;
		this.Go();
	};
	
	this.nextFrame  = function()
	{
		if(this.currentFrame < this.frameCount - 1)
		{
			this.Draw();
			return;
		}
		else
		{
			this.currentFrame = 0;
			this.Draw();
		};
	};

	this.faster = function()
	{
		if(this.framerate > 0)
			this.framerate = this.framerate - 200;
	};
	
	this.slower = function()
	{
		
		this.framerate = this.framerate + 200;		
	};
	
	this.previousFrame = function()
	{
		if(this.currentFrame > 2)
		{
			this.currentFrame = this.currentFrame - 2;
			this.Draw();
			return;
		}
		else
		{
			this.currentFrame = this.frameCount - 1;
			this.Draw();
			return;
		}
		return;
	};
	
	this.callFrame = function(frame)
	{
		this.currentFrame = frame;
	};
	
	this.controlBar = "		<b onclick=\"gallery.previousFrame()\" > Previous Picture</b> | \
							<b onclick=\"gallery.nextFrame()\">Next Picture</b>";
	
	this.videoControlBar = "<b onclick=\"gallery.togglePlayback()\"> play/pause </b> | \
							<b onclick=\"gallery.slower()\"> Slower </b> | \
							<b onclick=\"gallery.faster()\"> Faster </b>"
	
	//for POP effect
	this.aWindow = 0;
	this.bWindow = 0;
	this.cWindow = 0;
	
	this.aOpt = 0;
	this.bOpt = 0;
	this.cOpt = 0;
	
	this.aPhase = 0;
	this.bPhase = 0;
	this.cPhase = 0;
	
	this.Draw = function()
	{
		if(this.type == "SLIDESHOW" )
		{			
			var imageName = this.array[this.currentFrame]+"<br>";
			
			if(this.galleryMode)
				var imageCode = imageName+"<br>"+"<div id=\"imageBox\"> <img height=\"80%\" src=\"images/wedding/"+this.array[this.currentFrame]+"\"></div>"+"<br>"+this.videoControlBar+this.controlBar;
			else
				var imageCode = imageName+"<br>"+"<div id=\"imageBox\"> <img height=\"80%\" src=\"images/wedding/"+this.array[this.currentFrame]+"\"></div> "+"<br>"+this.controlBar;
			document.getElementById(this.frame).innerHTML = imageCode;	
			this.currentFrame++;
		}
		if(this.type == "POP" )
		{
			/*
			var trayFrame ;//= new BFrame(300,520,50,300);
			trayWindow = new BDirectWindow(trayFrame,"trayWindow",0,"TRAY_VIEW",0);
			trayMenu();
			trayWindow.Show();		
			
			barFrame = new BFrame(0,0,10,800);
			barWindow = new BDirectWindow(barFrame,"barWindow",0,"TRAY_VIEW",0);
			barMenu();
			barWindow.Show();
			*/
			
		};
	}
	
	this.galleryMode = 1;
	
	this.Go = function()
	{
		this.Draw();		

		if(this.currentFrame < this.frameCount - 1 && !this.lock)//
		{

			this.currentFrame++;			
			setTimeout(this.Go,this.framerate);
		}
		else
		{
			if(this.lock == 0)
			{
				this.currentFrame = 0;
				setTimeout(this.Go,this.framerate);
				document.getElementById("toolbar").innerHTML = "locked";
			}
			return;
		};	
		
	};
};


